package TCPUDP;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

public class Test {


    public static void main(String[] args) throws ClassNotFoundException, IOException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, NoSuchFieldException {

//        Properties prop = new Properties();
//
//        FileInputStream fis = new FileInputStream("F:\\IDEA\\wbk\\properties");
//
//        prop.load(fis);
//
//        String className = prop.getProperty("className");
//        String methodName = prop.getProperty("methodName");
//
//
//        Class<?> clazz = Class.forName(className);
//
//        Object o = clazz.getDeclaredConstructor().newInstance();
//
//        Method method = clazz.getDeclaredMethod(methodName);
//
//        method.invoke(o);

        Student s = new Student();
        s.setProperty(s,"name","wbk");
        s.showInfo();
    }
}


 class Student {
    private String name;
    private int age;

    public void setProperty(Object obj,String name,Object value) throws NoSuchFieldException, NoSuchMethodException, InstantiationException, IllegalAccessException {

        Class<?> clazz = obj.getClass();

        Field field = clazz.getDeclaredField(name);
        field.setAccessible(true);
        field.set(obj,value);

    }

    public Student() {
    }
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }
    // 自行补充getters and setters

    // 显示信息的方法
    public void showInfo() {
        System.out.println(name + " - " + age);
    }
}

class Teacher {
    private String name;
    int age;

    public void teach(){

        System.out.println("still teaching !");
    }

    public Teacher(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public Teacher() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}